<meta charset="utf-8">
<?php
// delete.php?week_number=<number>[&check=true]

// 判断参数是否完整
if (!isset($_GET['week_number']) || $_GET['week_number'] < 0) {
	die('参数错误');
}

// 判断是否已经确认删除
if (isset($_GET['check']) && $_GET['check'] == true) {
	include_once('database.php');

	// 删除全部
	$sql = "DELETE FROM courses ";
	if ($_GET['week_number'] > 0) {
		// 添加条件，只删除本周
		$sql .= "WHERE week_number=${_GET['week_number']}";
	}

	@mysqli_query($connection, $sql) or die('删除数据库失败：'.mysqli_error($connection));
	// 回到查看页面
	header("Location: table.php?action=view&week_number=${_GET['week_number']}");
}
?>

<!DOCTYPE html>
<html>
<head>
	<style type="text/css">
		body {
			text-align: center;
		}
		strong {
			color: red;
		}
		.action {
			padding: 0 32px;
			font-size: 20px;
		}
		.check {
			color: red;
			font-weight: bold;
		}
	</style>
</head>
<body>
	<?php if ($_GET['week_number'] == 0): ?>
	<h1>确定要删除<strong>全部</strong>周次的课程信息？</h1>
	<?php else: ?>
	<h1>确定要删除<strong>本周</strong>的课程信息？</h1>
	<?php endif ?>
	<!-- 取消删除 -->
	<a class="action" href="<?php echo "table.php?action=view&week_number=${_GET['week_number']}" ?>">打扰了</a>
	<!-- 继续删除 -->
	<a class="action check" href="<?php echo "?week_number=${_GET['week_number']}&check=true" ?>">确定</a>
</body>
</html>